package Lab6;

public class Password {
    String password;

    public Password(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Boolean isValid() {
        if (password.length() >= 5 && password.length() <= 9) {
            Boolean letterFlag = false;
            Boolean digitFlag = false;
            for (int i = 0; i < password.length(); i++) {
                char c = password.charAt(i);
                letterFlag |= Character.isLetter(c);
                digitFlag |= Character.isDigit(c);
                if (Character.isSpaceChar(c)) {
                    return false;
                }
                if (!Character.isLetter(c) && !Character.isDigit(c)) {
                    return false;
                }
            }
            return letterFlag && digitFlag;
        }
        return false;
    }
}
